import json

from myapp.utils import getPublicData


def getPageData():

    def mapFN(item):
        try:
            item.salary = json.loads(item.salary)
            item.companyPeople = json.loads(item.companyPeople)
            item.workTag = json.loads(item.workTag)
            if item.companyTags != '无':
                item.companyTags = json.loads(item.companyTags)[0].split('，')
            if not item.pratice:
                item.salary = list(map(lambda x: str(int(x / 1000)), item.salary))
            else:
                item.salary = list(map(lambda x: str(x), item.salary))
            item.salary = '-'.join(item.salary)
            item.companyPeople = list(map(lambda x: str(x), item.companyPeople))
            item.companyPeople = '-'.join(item.companyPeople)
        except Exception as err:
            print(f'--- err: {err}')

        return item

    jobs = getPublicData.getAllJobs()
    jobs = list(map(mapFN, jobs))
    return jobs